package com.tanhua.server.controller;

import com.tanhua.domain.vo.RecommendUserQueryVO;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    /**
     * 交友-今日佳人
     * GET tanhua/todayBest
     */
    @RequestMapping("todayBest")
    public ResponseEntity todayBest() {
        return tanhuaService.todayBest();
    }

    /**
     * 交友-推荐
     * GET/tanhua/recommendation
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserQueryVO vo) {
        return tanhuaService.recommendation(vo);
    }

    /**
     * 交友-佳人信息
     * GET /tanhua/:id/personalInfo
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Integer id) {
        return tanhuaService.personalInfo(id.longValue());
    }

    /**
     * 交友-查看陌生人问题
     * GET /tanhua/strangerQuestions
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity findStrangerQuestion(Long userId) {
        return tanhuaService.findStrangerQuestion(userId);
    }

    /**
     * 交友-回复陌生人问题
     * POST /tanhua/strangerQuestions
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyStrangerQuestions(@RequestBody Map map) {
        Long userId = Long.valueOf(map.get("userId").toString());
        String reply = (String) map.get("reply");
        return tanhuaService.replyStrangerQuestions(userId, reply);
    }

    /**
     * 交友-搜附近
     * GET /tanhua/search
     */
    @GetMapping("/search")
    public ResponseEntity searchNear(@RequestParam(required = false) String gender,
                                     @RequestParam(defaultValue = "2000") Integer distance) {
        return tanhuaService.searchNear(gender, distance);
    }

    /**
     * 探花-左滑右滑
     * GET/tanhua/cards
     */
    @GetMapping("/cards")
    public ResponseEntity cards() {
        return tanhuaService.cards();
    }

    /**
     * 探花-喜欢
     * GET/tanhua/:id/love
     */
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") Long likeUserId) {
        return tanhuaService.love(likeUserId);
    }

    /**
     * 探花-不喜欢
     * GET/tanhua/:id/unlove
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") Long likeUserId) {
        return tanhuaService.unlove(likeUserId);
    }

}